package vn.smartoffice.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import vn.smartoffice.entity.User;
import vn.smartoffice.mapper.UserMapper;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public User getCurrentUser() {
		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		if (auth != null) {
			return (User) auth.getPrincipal();
		} else {
			return null;
		}
	}

	@Override
	public Long getCurrentUserId() {
		User user = getCurrentUser();
		if (user != null) {
			return user.getId();
		} else {
			return null;
		}
	}

}
